Java 21 introduces the new Sequenced Collections API, which applies to all collections with a defined sequence on their elements, such as
LinkedList
, TreeSet
, and others (see JEP 431). For projects using Java 21 and
onwards, use this API instead of workaround implementations that were necessary before Java 21. One of the features of the new Sequenced Collections
API is SequencedCollection.reversed()
which returns a lightweight view of the original collection, in the reverse order.
This rule reports when reverse view would have been sufficient instead of a reverse copy of a sequenced collection created using a list constructor
plus a Collections.reverse(collection);
call.
If feasible, a view should be preferred over a copy because a view is a lightweight iterator without modification of the list itself.